<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <!-- 头部 -->
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
        background: isHeadBack ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0)',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#EEEEEE"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">我的积分</view>
      <view class="head_right" @click="goPage"> 积分明细 </view>
    </view>
    <!-- 主体 -->
    <view class="top">
      <view class="top_title">
        <view class="top_title_num">{{ userInfo.integral }}</view>
        <view class="top_title_text">积分</view>
      </view>
      <view class="top_btn" @click="transference">积分转让</view>
      <view class="top_right" @click="show = true">积分规则</view>
    </view>

    <scroll-view
      class="box"
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
    >
      <view class="box_title">每日任务 获取积分</view>
      

      <view class="box_item" v-for="(item, index) in list" :key="index">
        <view class="box_item_left">
          <view class="box_item_left_title">{{ item.name }}</view>
          <view class="box_item_left_integral">
            <image
              src="@/static/images/my/icon_wdjf_jifen.png"
              class="radio"
            ></image>
            <view>{{ item.every }}</view>
          </view>
        </view>
        <view
          class="box_item_right"
          :class="item.status == 1 ? 'box_item_right1' : ''"
          @click="toFinesh(item)"
          >{{ item.status == 1 ? "已完成" : "获取积分" }}</view
        >
      </view>
      <view :style="{height:'100rpx'}"></view>
      <u-modal
        :show="show"
        :title="title"
        :content="content"
        confirmColor="#55B877"
        :closeOnClickOverlay="true"
        @confirm="confirm"
        @close="confirm"
      ></u-modal>
    </scroll-view>


    <floatingBall></floatingBall>
  </view>
</template>
      
      <script>
export default {
  components: {},

  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      isHeadBack: false,
      show: false,
      title: "积分规则",
      content: "",
      list: [],
      userInfo: {},
      scrollHeihgt:0,
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".top").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - this.statusBarHeight;
        this.tabTop = data[0].height;
        console.log(data[0].height, "头部高度");
        console.log(data[1].height, "tab高度");
        console.log(data[2].height, "轮播高度");
        console.log(this.scrollHeihgt, "滚动区高度");
      });
    });

    // 积分规则
    this.$http
      .userPointRule({})
      .then((res) => {
        // console.log(res.data, 111111111);
        this.content = res.data.rule;
        // this.data = res.data.gongneng;
      })
      .catch((error) => {
        uni.$u.toast(error);
      });

    // 我的积分-任务列表
    this.$http
      .userMyPointTask({})
      .then((res) => {
        this.list = res.data.list;
        console.log(res.data, 222222222);
      })
      .catch((error) => {
        uni.$u.toast(error);
      });
    // 我的积分-积分记录
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let time = year + "-" + month;
    this.$http
      .userPointLog({ time: time, type: -1 })
      .then((res) => {
        console.log(res.data, "我的积分");
        this.userInfo = res.data.userInfo;
      })
      .catch((error) => {
        uni.$u.toast(error);
      });
  },
  methods: {
    scroll() {},
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    toFinesh(item) {
      if (item.status == 1) {
        uni.$u.toast("该任务今天已完成，明天再试试吧");
      } else {
        // 判断type跳到对应页面
        if (item.type == 1) {
          // 行者中心
          uni.navigateTo({
            url: "/pages/member/index",
          });
        } else if (item.type == 2) {
          // 奥义/大成
          let num = Math.floor(Math.random() * (3 - 1) + 1);
          if (num == 1) {
            // 跳奥义
            uni.navigateTo({
              url: "/pages/stargate/Tianwen",
            });
          } else {
            // 跳大成
            uni.navigateTo({
              url: "/pages/bigResult/bigResult",
            });
          }
        } else if (item.type == 3) {
          // 训练营

          uni.switchTab({
            url: "/pages/home/Training",
          });
        } else if (item.type == 4) {
          // 微创
          uni.switchTab({
            url: "/pages/home/minimalInvasive",
          });
        } else if (item.type == 5) {
          // 家族
          uni.navigateTo({
            url: `/pages/detail/myRecord?id=${this.userInfo.user_id}&type=my&from=my`,
          });
        } else if (item.type == 6) {
          // 星球列表
          uni.navigateTo({
            url: "/pages/distinguish/findStart",
          });
        } else if (item.type == 7) {
          // 共创
          uni.switchTab({
            url: "/pages/home/index",
          });
        }
      }
    },
    transference() {
      // uni.$u.toast("积分转让为会员专属，您还不是会员，请开通会员后再试");
      uni.navigateTo({
        url: "/pages/integral/transference",
      });
    },
    confirm() {
      this.show = false;
    },
    goPage() {
      uni.navigateTo({
        url: "/pages/integral/integralDetail",
      });
    },
  },
};
</script>
      
      <style scoped lang="scss">
.content {
  position: fixed;
  // background: #F7F8FA;
  box-sizing: border-box;
  background: url("/static/images/my/pic_wdjf_bwijing.png") no-repeat;
  background-size: 100% auto;
  background-attachment: fixed;
  // z-index: -10;
  display: flex;
  flex-direction: column;
}
// .scroll_view {
//   height: 100%;
// }
.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;
  background: #ffffff;
  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    color: #ffffff;
    font-size: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}
.top {
  position: relative;
  padding: 0 41rpx;
  .top_title {
    margin-top: 76rpx;
    // display: flex;
    .top_title_num {
      font-size: 80rpx;
      color: #ffffff;
      display: inline-block;
    }
    .top_title_text {
      font-size: 32rpx;
      color: #ffffff;
      margin-left: 9rpx;
      display: flex;
      display: inline-block;
    }
  }
  .top_btn {
    width: 230rpx;
    height: 72rpx;
    background: linear-gradient(180deg, #ffd1a2 0%, #ff9b34 100%);
    border-radius: 39rpx;
    text-align: center;
    line-height: 72rpx;
    font-size: 30rpx;
    color: #ffffff;
    margin-top: 48rpx;
  }
  .top_right {
    width: 174rpx;
    height: 56rpx;
    background: #ff932d;
    border-radius: 32rpx 0rpx 0rpx 32rpx;
    font-size: 28rpx;
    color: #ffffff;
    text-align: center;
    line-height: 56rpx;
    position: absolute;
    right: 0;
    top: 45rpx;
  }
}
.box {
  // flex: 1;
  background: #111111;
  border-radius: 32rpx 32rpx 0rpx 0rpx;
  margin-top: 52rpx;
  padding: 32rpx 30rpx;
  box-sizing: border-box;
  .box_title {
    font-size: 32rpx;
    color: #ffffff;
  }
  .box_item {
    margin-top: 32rpx;
    background: #272727;
    border-radius: 24rpx;
    display: flex;
    align-items: center;
    padding: 32rpx;
    .box_item_left {
      flex: 1;
      .box_item_left_title {
        font-size: 30rpx;
        color: #ffffff;
      }
      .box_item_left_integral {
        margin-top: 8rpx;
        display: flex;
        align-items: center;
        image {
          width: 28rpx;
          height: 28rpx;
        }
        view {
          font-size: 26rpx;
          color: #ff8a4c;
          margin-left: 12rpx;
        }
      }
    }
    .box_item_right {
      width: 180rpx;
      height: 64rpx;
      background: linear-gradient(360deg, #ff8400 0%, #ffb89c 100%);
      border-radius: 32rpx;
      font-size: 28rpx;
      color: #ffffff;
      text-align: center;
      line-height: 64rpx;
    }
    .box_item_right1 {
      width: 180rpx;
      height: 64rpx;
      background: #666666;
      border-radius: 32rpx;
      font-size: 28rpx;
      color: #ffffff;
      text-align: center;
      line-height: 64rpx;
    }
  }
}
</style>